package org.cttic.visualization.visualization.util.sixUtil;

import cn.hutool.json.JSONUtil;
import org.cttic.visualization.visualization.common.module.OnlineCData;
import org.cttic.visualization.visualization.common.module.provinceData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * @author shkstart
 * @create 2020-06-02 15:05
 */
@Component
public class OnlineCQueryUtil {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    public String queryUtil(String startTime,String endTime,int province,List<OnlineCData.vehArray> list){
        String querySql="SELECT sum(onlineCount) as onlineCount,sum(regCount) as regCount FROM `onlineCount` WHERE provinceId= '"+ province + "'" +
                " and processingTime<'"+endTime+"' and processingTime>'"+startTime+"'";
        System.out.println(querySql);
        OnlineCData.vehArray vehArray = new OnlineCData.vehArray();
        OnlineCData.vehArray.quota quota = new OnlineCData.vehArray.quota();

        Map<String, Object> stringObjectMap = jdbcTemplate.queryForMap(querySql);

        long totalOnline=0L;
        long total=0L;
        if(stringObjectMap!=null&&stringObjectMap.size()>0){
            cn.hutool.json.JSONObject jsonObject = JSONUtil.parseObj(stringObjectMap);
            Long onlineCount = jsonObject.getLong("onlineCount");
            Long regCount = jsonObject.getLong("regCount");
            quota.setOnlineCount(onlineCount+"");
            quota.setRegCount(regCount+"");
            vehArray.setProvinceId(province+"");
            vehArray.setProvinceName(provinceData.provinceID.get(province));
            vehArray.setQuotaInfo(quota);
            System.out.println("onlineCount:"+onlineCount);
            System.out.println("regCount:"+regCount);

            totalOnline+=onlineCount;


            total+=regCount;


            list.add(vehArray);
            System.out.println("totalOnline:"+totalOnline+"|"+total);
//            System.out.println("total:"+total);
            return totalOnline+"|"+total;
        }
        return null;
    }
}
